
function modelInit() {
    // $.cookie('TV_CST_userName', '王工头', {
    //     expires: 7
    // });
    var indexList = new TV.CookieOpt().getOpt()
    // console.log(indexList)
    // var index = indexList && indexList.index ? indexList.index : 0;
    var index = indexList && typeof indexList.index == 'number' ? indexList.index : undefined;
    var page = indexList && indexList.page ? indexList.page : 1;
    if (!modelIndex.disUser) {
        TV.UserMess()
    }
    //  TV.getHeader();
    getMessage(page, modelIndex.pageSize, 'next', index);
}

//标题过长滚动
function timedCount(index, str) {
    var elem = str;
    var thisContain = elem[index];
    console.info(thisContain);
    var thisIntro = elem[index].getElementsByClassName("sb");
    thisIntro[0].style.left = '0px';

    function Marquee() {
        var left = thisIntro[0].style.left;
        if (thisContain.offsetWidth < thisIntro[0].offsetWidth) {
            if (parseInt(left) > -thisIntro[0].offsetWidth) {
                thisIntro[0].style.left = (parseInt(left) - 1) + 'px';
            } else {
                thisIntro[0].style.left = '0px'
            }
        }
    }
    MyMar = setInterval(Marquee, 40);
}


/*
 * 1.右侧区
 */

cmsIndex.modules[cmsIndex.moduleGuid(cmsIndex.addModule())] = {
    modName: 'right',
    modNum: cmsIndex.moduleGuid(),
    map: {
        left: 0
    }
};

var right = cmsIndex.modules[cmsIndex.moduleGuid()].module = (function () {
    var mod = {
        modName: "pageList",
        modNum: cmsIndex.moduleGuid()
    },
        index = modelIndex.index, //位置
        isLike = modelIndex.isLike,//是否开启点赞功能
        special = modelIndex.special ? modelIndex.special : '',
        specialState = modelIndex.specialState,
        status = '1',//是否在外框
        length = 0, //真实长度
        nowPage = 1, //当前页数
        totalPage = 1,  //总页数
        type = modelIndex.type,//类型
        listName = modelIndex.listName,  //模块名
        pageSize = modelIndex.pageSize,//模块数量
        rowHeight = modelIndex.rowHeight,//多行模块行数
        containerId = modelIndex.containerId; //包含模块的标签id

    //操作
    mod.toggleFocus = function (number) {
        var me = mod;
        if (number != undefined) {
            index = number;
        }
        var elem = $("#" + containerId).children("." + listName);
        for (i = 0; i < length; i++) {
            elem[i].className = listName;

        }
        var len = $('#' + containerId).children("." + listName).length;
        console.log(index,len-1)
        if (index >= len - 2) {
            index = 2
        }else if(index <2){
            index =len-3
        }
        

        if (elem.length) {

            elem[index].className = elem[index].className + ' active';

            elem[index + 1].className = elem[index + 1].className + ' z-20';
            elem[index - 1].className = elem[index - 1].className + ' z-20';

            elem[index + 2].className = elem[index + 2].className + ' z-10';
            elem[index - 2].className = elem[index - 2].className + ' z-10';

        }

        if (index > 2) {
            $("#list-con").css("left", -(index - 2) * 168 + "px");
        } else {
            $("#list-con").css("left", "-40px");

        }
        
        $(".list-title").html(mess.items[index-2].title)
        
        $(".list-content").html(mess.items[index-2].brief)





        return me;
    };
    //赋值
    mod.initialization = function () {
        var me = mod;
        nowPage = parseInt(document.getElementById('now_page').innerHTML);
        totalPage = parseInt(document.getElementById('total_page').innerHTML);
        length = $('#' + containerId).children("." + listName).length;
        return me;
    };
    //index 位置调整
    mod.moveOp = function (directive) {
        var me = mod;
        console.log(specialState, nowPage)
        var json = new TV.ListOperation({
            type: type,
            key: directive,
            isLike: isLike,
            status: status,
            nowPage: nowPage,
            totalPage: totalPage,
            pageSize: pageSize,
            length: length,
            index: index,
            rowHeight: rowHeight
        })
        var message = json.operation();
        console.log(message)
        index = message.index;
        status = message.status;
        if (message.position != '') {
            getMessage(message.nowPage, pageSize, message.position);  //下一页
        }
        mod.toggleFocus();
        return me;
    };
    mod.action = function (directive) {
        var me = mod;
        switch (directive) {
            case 'back':
                history.go(-1);
                break;
            case 'enter':
                if (isCache) {
                    var cookieTv = new TV.CookieOpt({
                        index: index,
                        page: nowPage
                    })
                    var indexList = cookieTv.setOpt();
                }

                direEnter(index);

                break;
        }
        return me;
    };
    mod.grabEvent = function (key) {
        var me = mod;
        var keyJson = TV.GetKey(key);
        if (keyJson.keyState && keyJson.keyState != 'enter' && keyJson.keyState != 'back') {
            me.moveOp(keyJson.keyState);
        } else {
            me.action(keyJson.keyState)
        }
        return keyJson.isBlock;


    };

    return mod;
})();

cmsIndex.run();